package com.gitee.sidihuo.utils.util;

import org.apache.commons.lang3.StringUtils;

public class IdGenerator {

    /**
     * 240121140242329
     * 15位 yyMMddHHmmssSSS
     */
    public static String generatorId15() {
        return TimeFormatter.formatCurrent(TimeFormatter.FORMATTER_SHORT);
    }

    /**
     * 15位+1随机数 yyMMddHHmmssSSS + X
     */
    public static String generatorId16WithRandom1() {
        return generatorId15() + random1();
    }

    /**
     * 15位+2随机数 yyMMddHHmmssSSS + XX
     */
    public static String generatorId17WithRandom2() {
        return generatorId15() + random2();
    }

    /**
     * 15位+3随机数 yyMMddHHmmssSSS + XXX
     */
    public static String generatorId18WithRandom3() {
        return generatorId15() + random3();
    }

    /**
     * 15位+4随机数 yyMMddHHmmssSSS + XXXX
     */
    public static String generatorId19WithRandom4() {
        return generatorId15() + random4();
    }

    /**
     * 15位+5随机数 yyMMddHHmmssSSS + XXXXX
     */
    public static String generatorId20WithRandom5() {
        return generatorId15() + random5();
    }

    /**
     * 15位+7随机数 yyMMddHHmmssSSS + XXXXXXX
     */
    public static String generatorId22WithRandom7() {
        return generatorId15() + random7();
    }

    /**
     * 15位+10随机数 yyMMddHHmmssSSS + XXXXXXXXXX
     */
    public static String generatorId25WithRandom10() {
        return generatorId15() + random10();
    }

    public static String generatorIdWithSeq(String id, int seq, int seqLength) {
        String seqStr = String.valueOf(seq);
        String string = StringUtils.leftPad(seqStr, seqLength, "0");
        return id + string;
    }

    /**
     * 0 到 1 的 double 值
     */
    public static double random() {
        double random = Math.random();
        return random;
    }

    /**
     * 0 到 1 的 double.toString 值
     */
    public static String randomNumString() {
        double random = random();
        String string = String.valueOf(random);
        return string;
    }

    public static String random1() {
        String string = randomNumString();
        if (string.length() > 3) {
            String substring = string.substring(2, 3);
            return substring;

        } else {
            return "1";
        }
    }

    public static String random2() {
        String string = randomNumString();
        if (string.length() > 4) {
            String substring = string.substring(2, 4);
            return substring;

        } else {
            return "12";
        }
    }

    public static String random3() {
        String string = randomNumString();
        if (string.length() > 5) {
            String substring = string.substring(2, 5);
            return substring;
        } else {
            return "123";
        }
    }

    public static String random4() {
        String string = randomNumString();
        if (string.length() > 6) {
            String substring = string.substring(2, 6);
            return substring;
        } else {
            return "1234";
        }
    }

    public static String random5() {
        String string = randomNumString();
        if (string.length() > 7) {
            String substring = string.substring(2, 7);
            return substring;
        } else {
            return "12345";
        }
    }

    public static String random6() {
        String string = randomNumString();
        if (string.length() > 8) {
            String substring = string.substring(2, 8);
            return substring;
        } else {
            return "123456";
        }
    }

    public static String random7() {
        String string = randomNumString();
        if (string.length() > 9) {
            String substring = string.substring(2, 9);
            return substring;
        } else {
            return "1234567";
        }
    }

    public static String random8() {
        String string = randomNumString();
        if (string.length() > 10) {
            String substring = string.substring(2, 10);
            return substring;
        } else {
            return "12345678";
        }
    }

    public static String random9() {
        String string = randomNumString();
        if (string.length() > 11) {
            String substring = string.substring(2, 11);
            return substring;
        } else {
            return "123456789";
        }
    }

    public static String random10() {
        String string = randomNumString();
        if (string.length() > 12) {
            String substring = string.substring(2, 12);
            return substring;
        } else {
            return "1234567890";
        }
    }
}
